package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_match;

import cn.com.api.service.ApiU_matchService;

import cn.com.util.*;


public class U_matchBaseController {

	private static Logger logger = Logger.getLogger(U_matchBaseController.class);
	
	@Autowired
	private ApiU_matchService apiU_matchService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "u_match-list")
	public ModelAndView u_match_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_match_list.jsp");
		
		List<ApiU_match> u_matchs = apiU_matchService.findU_matchs();
		mv.addObject("u_matchs", u_matchs);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "u_match-add-pre")
	public ModelAndView u_match_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_match_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiU_match u_match = apiU_matchService.findU_matchById(Integer.valueOf(id));
			mv.addObject("u_match",u_match);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "u_match-add")
	public void u_match_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String match_id = request.getParameter("match_id");
		String match_name = request.getParameter("match_name");
		String join_count = request.getParameter("join_count");
		String ent_id = request.getParameter("ent_id");
		String amount = request.getParameter("amount");
		String match_introduce = request.getParameter("match_introduce");
		String match_rules = request.getParameter("match_rules");
		String thumbnail = request.getParameter("thumbnail");
		String thumbnail_h5 = request.getParameter("thumbnail_h5");
		String pstart_time = request.getParameter("pstart_time");
		String pend_time = request.getParameter("pend_time");
		String vstart_time = request.getParameter("vstart_time");
		String vend_time = request.getParameter("vend_time");
		String result_time = request.getParameter("result_time");
		String counter_fee = request.getParameter("counter_fee");
		String bonus_amount = request.getParameter("bonus_amount");
		String status = request.getParameter("status");
		String reject_reason = request.getParameter("reject_reason");
		String is_pay = request.getParameter("is_pay");
		String win_amount = request.getParameter("win_amount");
		String guess_amount = request.getParameter("guess_amount");
		String is_need_vedio = request.getParameter("is_need_vedio");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		String ext4 = request.getParameter("ext4");
		String ext5 = request.getParameter("ext5");
		String audit_by = request.getParameter("audit_by");
		String audit_time = request.getParameter("audit_time");
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiU_match u_match = new ApiU_match();
            /*
		    u_match.setMatch_id(match_id);
		    u_match.setMatch_name(match_name);
		    u_match.setJoin_count(join_count);
		    u_match.setEnt_id(ent_id);
		    u_match.setAmount(amount);
		    u_match.setMatch_introduce(match_introduce);
		    u_match.setMatch_rules(match_rules);
		    u_match.setThumbnail(thumbnail);
		    u_match.setThumbnail_h5(thumbnail_h5);
		    u_match.setPstart_time(pstart_time);
		    u_match.setPend_time(pend_time);
		    u_match.setVstart_time(vstart_time);
		    u_match.setVend_time(vend_time);
		    u_match.setResult_time(result_time);
		    u_match.setCounter_fee(counter_fee);
		    u_match.setBonus_amount(bonus_amount);
		    u_match.setStatus(status);
		    u_match.setReject_reason(reject_reason);
		    u_match.setIs_pay(is_pay);
		    u_match.setWin_amount(win_amount);
		    u_match.setGuess_amount(guess_amount);
		    u_match.setIs_need_vedio(is_need_vedio);
		    u_match.setExt1(ext1);
		    u_match.setExt2(ext2);
		    u_match.setExt3(ext3);
		    u_match.setExt4(ext4);
		    u_match.setExt5(ext5);
		    u_match.setAudit_by(audit_by);
		    u_match.setAudit_time(audit_time);
	        */
			apiU_matchService.insertU_match(u_match);
		}
		//edit
		else{
			ApiU_match u_match = apiU_matchService.findU_matchById(Integer.valueOf(id));
	        /*
		    u_match.setMatch_id(match_id);
		    u_match.setMatch_name(match_name);
		    u_match.setJoin_count(join_count);
		    u_match.setEnt_id(ent_id);
		    u_match.setAmount(amount);
		    u_match.setMatch_introduce(match_introduce);
		    u_match.setMatch_rules(match_rules);
		    u_match.setThumbnail(thumbnail);
		    u_match.setThumbnail_h5(thumbnail_h5);
		    u_match.setPstart_time(pstart_time);
		    u_match.setPend_time(pend_time);
		    u_match.setVstart_time(vstart_time);
		    u_match.setVend_time(vend_time);
		    u_match.setResult_time(result_time);
		    u_match.setCounter_fee(counter_fee);
		    u_match.setBonus_amount(bonus_amount);
		    u_match.setStatus(status);
		    u_match.setReject_reason(reject_reason);
		    u_match.setIs_pay(is_pay);
		    u_match.setWin_amount(win_amount);
		    u_match.setGuess_amount(guess_amount);
		    u_match.setIs_need_vedio(is_need_vedio);
		    u_match.setExt1(ext1);
		    u_match.setExt2(ext2);
		    u_match.setExt3(ext3);
		    u_match.setExt4(ext4);
		    u_match.setExt5(ext5);
		    u_match.setAudit_by(audit_by);
		    u_match.setAudit_time(audit_time);
			*/
			apiU_matchService.updateU_match(u_match);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
        JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "u_match-delete")
	public void u_match_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiU_matchService.deleteU_match(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
}



